package com.cxc.simple;

public class DeadThread {


    public static void main(String[] args) {
        deadExample();
    }
    private static void deadExample() {

        final Object o1 = new Object();
        final Object o2 = new Object();

        Runnable r1 = () -> {
            synchronized (o1) {
                System.out.println("r1 get o1 lock");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                synchronized (o2) {
                    System.out.println("r1 get o2 lock");
                }
            }
        };

        Runnable r2=()->{
            synchronized (o2){
                System.out.println("r2 get o2 lock");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                synchronized (o1){
                    System.out.println("r2 get o1 lock");
                }
            }
        };

        new Thread(r1,"thread1").start();
        new Thread(r2,"thread2").start();


    }
}


